*********************************************************************************
/*    Cumulative share of revenue collected each year 	*/
*********************************************************************************
clear all

* File paths
local datapath "${mvpf_audits}/data/cleaned" 
local graphpath "${graphpath}" 
local datafolder "${mvpf_audits}/data/outside" 
local dofilepath "${mvpf_audits}/code/prep" 


* Version of fig to produce 
global version ${version} // paper or slides

* Other formatting
if "${version}" == "slides" {
	global title "title(" ", size(vhuge))"
	global img wmf
	graph set window fontface "Arial"
	global title "title(" ", size(vhuge))"
	global axis_size "" //xsize(6.5) ysize(4)" // makes figure wider
}

else if "${version}" == "paper" {
	global title "title("")"
	global img pdf
	graph set window fontface "LMRoman10-Regular"
	global title " "
	global axis_size " " // makes figure wider
}

use "${mvpf_audits}/data/figures_rep/ap5.dta", clear

* Revenue
tw  (connected share_rev year if tpi_pctl10 == 0 & year>=-3) ///
	(connected share_rev year if tpi_pctl10 == 50 & year>=-3) ///
	(connected share_rev year if tpi_pctl10 == 90 & year>=-3) ///
	(connected share_rev year if tpi_pctl10 == 99 & year>=-3) ///
	(connected share_rev year if tpi_pctl10 == 999 & year>=-3) ///
	, ///
	xline(7 11, lc(gs11)) ///
	xtitle("Years since tax year") ytitle("Share total audit revenue collected") ///
	legend(ring(0) pos(11) col(1) symxsize(*0.5) order(5 4 3 2 1)  ///
	lab(1 "0-50") lab(2 "50-90") lab(3 "90-99") lab(4 "99-99.9") lab(5 "99.9+")) ///
	ylab( , nogrid format(%09.1fc)) ///
	xlab(0(3)18) xscale(r(0 18)) ///
	///title("`y' `spec_lab' Audits (wins)", color(black) size(5.5)) ///
	${title} ${axis_size} 
graph export "`graphpath'/rev_share_`y'_`spec'_wins.wmf", as(wmf) replace

* Labor costs
tw  (connected share_costs year if tpi_pctl10 == 0 & year>=-3) ///
	(connected share_costs year if tpi_pctl10 == 50 & year>=-3) ///
	(connected share_costs year if tpi_pctl10 == 90 & year>=-3) ///
	(connected share_costs year if tpi_pctl10 == 99 & year>=-3) ///
	(connected share_costs year if tpi_pctl10 == 999 & year>=-3) ///
	, ///
	xline(7 11, lc(gs11)) ///
	xtitle("Years since tax year") ytitle("Share total wage costs accrued") ///
	legend(ring(0) pos(11) col(1) symxsize(*0.5) order(5 4 3 2 1)  ///
	lab(1 "0-50") lab(2 "50-90") lab(3 "90-99") lab(4 "99-99.9") lab(5 "99.9+")) ///
	ylab( , nogrid format(%09.1fc)) ///
	xlab(0(3)18) xscale(r(0 18)) ///
	///title("`y' `spec_lab' Audits", color(black) size(5.5)) ///
	${title} ${axis_size} 
graph export "`graphpath'/costs_share_`y'_`spec'_wins.wmf", as(wmf) replace
	
* Labor costs - animation for slides
if "${version}" == "slides" {
tw  (connected share_costs year if tpi_pctl10 == 0 & year>=-3, lc(white) mc(white)) ///
	(connected share_costs year if tpi_pctl10 == 90 & year>=-3, lc(white) mc(white)) ///
	(connected share_costs year if tpi_pctl10 == 99 & year>=-3, lc(white) mc(white)) ///
	(connected share_costs year if tpi_pctl10 == 999 & year>=-3, lc(white) mc(white)) ///
	(connected share_costs year if tpi_pctl10 == 50 & year>=-3, lc(oi2) mc(oi2)) ///
	, ///
	xline(7 11, lc(gs11)) ///
	xtitle("Years since tax year") ytitle("Share total wage costs accrued") ///
	legend(ring(0) pos(11) col(1) symxsize(*0.5) order(5 4 3 2 1)  ///
	lab(1 "0-50") lab(2 "50-90") lab(3 "90-99") lab(4 "99-99.9") lab(5 "99.9+")) ///
	ylab( , nogrid format(%09.1fc)) ///
	xlab(0(3)18) xscale(r(0 18)) ///
	///title("`y' `spec_lab' Audits", color(black) size(5.5)) ///
	${title} ${axis_size} 
graph export "`graphpath'/costs_share_`y'_`spec'_wins_tpi50_90.wmf", as(wmf) replace

}
